package com.limf.demo.java8;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

public class Test8 {

	public static void main(String[] args) {
		
		// 测试接口默认方法
		// testInterface();
		
		// 1.8版本前（老版本）的排序
		// testSortList();
		
		testConverter2();
	}
	
	static void testInterface() {
		Formula formula = new Formula() {

			@Override
			public double calculate(int a) {
				// TODO Auto-generated method stub
				return sqrt(a * 100);
			}
		};
		System.out.println(formula.calculate(100));    // 100.0
		System.out.println(formula.sqrt(16));      // 4.0
	}
	
	static void testSortList() {
		
		List<String> names = Arrays.asList("peter", "anna", "mike", "xenia");
		/*Collections.sort(names, new Comparator<String>() {
			@Override
			public int compare(String o1, String o2) {
				// TODO Auto-generated method stub
				return o2.compareTo(o1);
			}
		});*/
		/*
		Collections.sort(names, (String a, String b)->{
			System.out.println("abc");
			return b.compareTo(a);
		});*/
		//Collections.sort(names, (String a, String b) -> b.compareTo(a));
		Collections.sort(names, (a, b) -> b.compareTo(a));
		
		for(Iterator<String> i = names.iterator(); i.hasNext();) {
			System.out.println(i.next());
		}
		
	}
	
	static void testConverter() {

		// Converter<String, Integer> converter = (from) -> Integer.valueOf(from);
		// Converter<String, Integer> converter = Integer::valueOf;
		Something something = new Something();
		//Converter<String, String>converter = something::endWith;
		// String converted = converter.convert("Java");
		// System.out.println(converted);    // J
		Converter<String, Something> converter = Something::new;
		Something something2 = converter.convert("constructors");

	}
	
	static void testConverter2() {
		//final int num = 1;
		int num = 1;
		
		Converter<Integer, String> StringConverter = (from) -> String.valueOf(from + num);
		System.out.println(StringConverter.convert(2));   // 3
		//num = 3;
	}
	
	static void testPersonFactory() {
		PersonFactory<Person> factory = Person::new;
		Person person = factory.create("Peter", "Parker");
	}
}
